View Javadoc
1 /* 2 * Title: S/MIME Project 3 * Description: S/MIME email sending capabilities 4 * @Author Vladimir Radisic 5 * @Version 2.0.1 6 */ 7 8 9 package org.webdocwf.util.smime.cms; 10 11 12 import org.webdocwf.util.smime.exception.SMIMEException; 13 import org.webdocwf.util.smime.der.DERSet; 14 import org.webdocwf.util.smime.der.DERSequence; 15 import org.webdocwf.util.smime.der.DERInteger; 16 17 18 /*** 19 * Capabilities which this class can indicate are capabilities of symetric 20 * encryption algorithm: DES_EDE3_CBC, RC2_CBC with 128bit key, RC2_CBC with 21 * 64bit key, DES and RC2_CBC with 40bit key. Capabilities Attributes are one of 22 * Signed Attributes and are used for creating CMS objects for signed messages. 23 */ 24 public class CapabilitiesAttribute extends Attribute { 25 26 /*** 27 * Constructs capabilities from given list with information about algorithm 28 * @param capabilities0 is array of Strings with element corresponds to 29 * appropriate algorithm (list of algorithms). 30 * @exception SMIMEException in case of unknown type of Capabilities Attributes. 31 * Also, it can be thrown from super class constructor or its addContent method. 32 */ 33 public CapabilitiesAttribute(String[] capabilities0) throws SMIMEException { 34 super("ID_SMIMECAPABILITIES", "NAME_STRING"); 35 DERSet capabilSet = new DERSet(); 36 DERSequence capabilSequ = new DERSequence(); 37 38 for (int i = 0; i != capabilities0.length; i++) { 39 if (capabilities0[i] == null) 40 continue; 41 else if (capabilities0[i].equalsIgnoreCase("RC2_CBC_40") | capabilities0[i].equalsIgnoreCase("RC2_CBC_64") | capabilities0[i].equalsIgnoreCase("RC2_CBC_128")) { 42 AlgorithmIdentifier rc2 = new AlgorithmIdentifier("RC2_CBC", "NAME_STRING"); 43 Integer keyLeng = new Integer(capabilities0[i].substring(9)); 44 45 rc2.addParamToAlgorithmId((new DERInteger(keyLeng.intValue())).getDEREncoded()); 46 capabilSequ.addContent(rc2.getDEREncoded()); 47 } else if (capabilities0[i].equalsIgnoreCase("DES_EDE3_CBC") | capabilities0[i].equalsIgnoreCase("DES")) { 48 AlgorithmIdentifier desede3 = new AlgorithmIdentifier(capabilities0[i], "NAME_STRING"); 49 50 desede3.addNullToAlgorithmId(); 51 capabilSequ.addContent(desede3.getDEREncoded()); 52 } else if (capabilities0[i].equalsIgnoreCase("MD2_WITH_RSA") | capabilities0[i].equalsIgnoreCase("MD5_WITH_RSA") | capabilities0[i].equalsIgnoreCase("SHA1_WITH_RSA") | capabilities0[i].equalsIgnoreCase("SHA1_WITH_DSA") | capabilities0[i].equalsIgnoreCase("RSA")) { 53 AlgorithmIdentifier rsa = new AlgorithmIdentifier(capabilities0[i], "NAME_STRING"); 54 55 capabilSequ.addContent(rsa.getDEREncoded()); 56 } else 57 throw new SMIMEException(this, 1020); 58 } 59 capabilSet.addContent(capabilSequ.getDEREncoded()); 60 super.addContent(capabilSet.getDEREncoded()); 61 } 62 } 63

This page was automatically generated by Maven